#include <algorithm>
#include "MediaLibrary.h"

Song* MediaLibrary::CreateSong(std::string name, std::string interpret, Album * album, TDuration duration){
	//create a new Song
	Song* newsong = new Song(name, interpret, album, duration);
	//store the Song in the library
	mLibrary.push_back(newsong);
	//return the Song
	return newsong;
}

Album* MediaLibrary::CreateAlbum(std::string const& albumname, std::string const& albuminterpret){
	//create a new Album
	Album* newalbum = new Album(albumname, albuminterpret);
	//store the Album in the library
	mLibrary.push_back(newalbum);
	//return the Album
	return newalbum;
}

MusicCollection* MediaLibrary::CreateCollection(std::string const& collectionname){
	//create a new MusicCollection
	MusicCollection* newcollection = new MusicCollection(collectionname);
	//store the MusicCollection in the library
	mLibrary.push_back(newcollection);
	//return the MusicCollection
	return newcollection;
}

void MediaLibrary::deletemedia(MusicMedia * media){
	//free memory in the list mLibrary
	delete media; media = 0;
}

MediaLibrary::~MediaLibrary(){
	//free memory of each entry in the list
	std::for_each(mLibrary.begin(), mLibrary.end(), deletemedia);
	//clear the list
	mLibrary.clear();
}